// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Continue Setup Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 39 : TYPE_CONTINUESETUP


// Static Values

// Tables

event ObjectMain
	switch object.state
	case 0
		stage.pauseEnabled = 0
		object.value0 = 320
		SetClassicFade(0, 0, 0, object.value0)
		object.state++
		break
	case 1
		if object.value0 > 0
			object.value0 -= 8
		else
			object[0].yvel = 0x30000
			if object[1].type != TypeName[Blank Object]
				object[1].yvel = 0x30000
			end if
			PlayMusic(0)
			object.state++
		end if
		SetClassicFade(0, 0, 0, object.value0)
		break
	case 2
		temp0 = 0
		switch stage.playerListPos
		case 0
		case 3
		default
			temp1 = 0xAC0000
			break
		case 1
			temp1 = 0xB10000
			break
		case 2
		case 4
			temp1 = 0xA80000
			break
		case 5
			temp1 = 0xAC0000
			break
		end switch
		temp2 = temp1
		temp2 += 0x80000
		object[0].animationSpeed = 60
		if object[0].ypos >= temp2
			object[0].ypos = temp1
			object[0].yvel = 0
			object[0].animation = ANI_CONTINUE
			temp0++
		end if
		if object[1].type == TypeName[Blank Object]
			temp0++
		else
			object[1].animationSpeed = 60
			if object[1].ypos >= 0xB90000
				object[1].ypos = 0xB10000
				object[1].yvel = 0
				object[1].animation = ANI_CONTINUE
				temp0++
			end if
		end if
		if temp0 == 2
			object.state++
			object[+2].state++
		end if
		break
	case 3
		checkEqual(inputPress.buttonA, 1)
		temp0 = checkResult
		checkEqual(inputPress.buttonB, 1)
		temp0 |= checkResult
		checkEqual(inputPress.buttonC, 1)
		temp0 |= checkResult
		checkEqual(inputPress.start, 1)
		temp0 |= checkResult
		
		if temp0 == 1
			object[0].animation = ANI_CONTINUE_UP
			object[0].speed = 0
			if stage.playerListPos == 2
				object[0].ypos -= 0x20000
			else
				object[0].ypos -= 0x60000
			end if
			PlaySfx(SfxName[Charge], 0)
			object.state++
			object[+2].state++
		else
			if stage.playerListPos == 8
				if object[0].frame == 1
					if object.value2 == 0
						CreateTempObject(TypeName[Continue Setup], 1, object[0].xpos, object[0].ypos)
						object[tempObjectPos].state = 9
						object[tempObjectPos].priority = PRIORITY_ACTIVE
						object[tempObjectPos].drawOrder = 6
						object[tempObjectPos].frame = 0
						object.value2 = 1
					end if	
				else
					object.value2 = 0
				end if	
			end if			
		end if
		break
	case 4
		if music.volume > 0
			music.volume--
		end if
		object[0].speed += 0x2000
		if object[0].speed == 0x90000
			object[0].xvel = 0x100000
			if object[1].type == TypeName[Blank Object]
				object.state++
			end if
		end if
		if object[1].type != TypeName[Blank Object]
			if object[0].speed == 0x20000
				object[1].animation = ANI_CONTINUE_UP
				object[1].speed = 0
				object[1].ypos -= 0x60000
				PlaySfx(SfxName[Charge], 0)
			end if
			if object[0].speed > 0x20000
				object[1].speed += 0x2000
				if object[1].speed == 0x90000
					object[1].xvel = 0x100000
					object.state++
				end if
			end if
		end if
		break
	case 5
		if music.volume > 0
			music.volume--
		end if
		temp0 = screen.xsize
		temp0 += 32
		if object[1].type == TypeName[Blank Object]
			temp1 = object[0].xpos
		else
			temp1 = object[1].xpos
		end if
		temp1 >>= 16
		if temp1 >= temp0
			object.state++
		end if
		break
	case 6
		if music.volume > 0
			music.volume--
		end if
		object.value0 += 4
		SetClassicFade(0, 0, 0, object.value0)
		if object.value0 == 384
			player.continues--
			if options.gameMode == 1
				arrayPos1 = options.saveSlot
				arrayPos1 <<= 3
				arrayPos1 += 1000
				arrayPos1 += 7		
				saveRAM[arrayPos1] = player.continues
				WriteSaveRAM()
			end if
			player.lives = 3
			fadeColor = 0
			object.value0 = 0
			lampPostID = 0
			object.direction = FLIP_NONE
			stage.activeList = recStageList
			stage.listPos = recStage
			LoadStage()
		end if
		break
	case 7
		object.value0 += 4
		SetClassicFade(0, 0, 0, object.value0)
		if object.value0 == 384
			fadeColor = 0
			object.value0 = 0
			lampPostID = 0
			object.direction = FLIP_NONE
			recAnimation = 0
			stage.activeList = PRESENTATION_STAGE
			stage.listPos = StageName[P - MAIN MENU]
			LoadStage()
		end if
		break
	case 9	
		object.value0++
		object.xpos += 0xC000
		object.ypos += 0x2000
		if object.value0 == 10
			object.frame++
		end if
		if object.value0 == 30
			object.type = TypeName[Blank Object]
		end if
		break
	end switch
end event


event ObjectDraw
	if object.propertyValue == 0
		ClearScreen(1)
	else
		DrawSprite(object.frame)
	end if	
end event


event ObjectStartup
	if object.propertyValue == 0
		foreach (TypeName[Continue Setup], arrayPos0, ALL_ENTITIES)
			object[arrayPos0].drawOrder = 0
		next
		object[0].xpos = screen.xcenter
		object[0].xpos <<= 16
		object[0].animation = ANI_FANROTATE
		object[0].state = PlayerObject_HandleRunSpd2
		object[0].yvel = 0x30000
		if object[1].type != TypeName[Blank Object]
			object[1].xpos = screen.xcenter
			object[1].xpos <<= 16
			object[1].animation = ANI_FANROTATE
			object[1].state = PlayerObject_HandleRunSpd2
			object[1].yvel = 0x30000
			object[0].xpos += 0x200000
			object[1].xpos -= 0x200000
			object[1].ypos += 0x50000
		end if
		switch stage.playerListPos
		case 0
		case 3
			break
		case 1
			object[0].ypos += 0x50000
			break
		case 2
		case 4
			object[0].ypos -= 0x40000
			break
		end switch
		stage.newXBoundary2 = screen.xsize
		stage.newYBoundary2 = screen.ysize
		switch saved.dokiTracks
		case 0
			temp0 = 0
			break
		case 1
			temp0 = 1
			break
		case 2
			CheckGreater(stage.playerListPos, 5)
			temp0 = checkResult
			break
		end switch
		if temp0 == 1
			SetMusicTrack("DokiMix/Continue.ogg", 0, 0)
		else
			SetMusicTrack("Continue.ogg", 0, 0)
		end if	
		if player.continues == 0
			player.continues = 3
		end if
	end if
	LoadSpriteSheet("Players/Yuri1.gif")
	SpriteFrame(-3, -3, 5, 5, 221, 162)
	SpriteFrame(-3, -3, 5, 5, 227, 162)
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
